<?php
/*由bean脚本生成 powerBy--joe*/
namespace app\common\manage;
use app\common\validate\OrderGoodsDetailValidate;
use app\common\model\OrderGoodsDetailModel;
use app\common\bean\OrderGoodsDetailBean;
use app\common\bean\ListMap;
use app\common\utils\TimeUtil;
use app\common\exception\MyException;
use Exception;
class OrderGoodsDetailManage extends BaseManage
{
	/**
	* @return OrderGoodsDetailManage
	*/
	static function getInstance(){
		return parent::getInstance();
	}

	
	/**
	 * @desc 获取分页数据
	 * @param ListMap $listMap
	 * @return ListMap $listMap
	 * @throws Exception
	**/
	public function getPaginatorList(ListMap $listMap) {
		$conditionMap = new ListMap();
		if($timeArray = TimeUtil::getInstance()->dealBetweenTime($listMap))
		$conditionMap->setParameter(OrderGoodsDetailBean::$alias.POINST.OrderGoodsDetailBean::$createdAt,$timeArray);
		$conditionMap->setAlias(OrderGoodsDetailBean::$alias);
		$listMap->setField(OrderGoodsDetailBean::$alias.ALL_FIELD);
		!$this->getParamBool($listMap,"orderFieldName") ?: $conditionMap->setOrder($listMap->getParameter('orderFieldName').SPACE.$listMap->getParameter('orderType'));
		// Todo:添加业务处理代码...


		//自行选择是连表查询还是单表查询,默认单表
		//$resultMap = OrderGoodsDetailModel::getInstance()->getJoinList($conditionMap);
		$resultMap = OrderGoodsDetailModel::getInstance()->getList($conditionMap);
		$resultMap?:MyException::throwMyException("查询数据失败");
		return $resultMap;
	}
	
	/**
	 * @desc 添加数据
	 * @param OrderGoodsDetailBean $orderGoodsDetailBean
	 * @return int int
	 * @throws Exception
	**/
	public function add($orderGoodsDetailBean) {
		OrderGoodsDetailValidate::getInstance()->goCheck(OrderGoodsDetailValidate::$add,$orderGoodsDetailBean->getData());
		// Todo:添加业务处理代码...


		$orderGoodsDetailBean->setCreatedAt(TimeUtil::getInstance()->getTimeNow());
		$result = OrderGoodsDetailModel::getInstance()->addDataGetInsertId($orderGoodsDetailBean->getData());
		$result ?: MyException::throwMyException("插入数据失败");
		return $result;
	}
	
	/**
	 * @desc 编辑数据
	 * @param OrderGoodsDetailBean $orderGoodsDetailBean
	 * @return int int
	 * @throws Exception
	**/
	public function edit($orderGoodsDetailBean) {
		OrderGoodsDetailValidate::getInstance()->goCheck(OrderGoodsDetailValidate::$edit,$orderGoodsDetailBean->getData());
		// Todo:添加业务处理代码...


		$result = OrderGoodsDetailModel::getInstance()->updatedData([OrderGoodsDetailBean::$id => $orderGoodsDetailBean->getId()],$orderGoodsDetailBean->getData());
		$result ?: MyException::throwMyException("更新失败");
		return $result;
	}
	
	/**
	 * @desc 删除数据
	 * @param OrderGoodsDetailBean $orderGoodsDetailBean
	 * @return int int
	 * @throws Exception
	**/
	public function delete($orderGoodsDetailBean) {
		OrderGoodsDetailValidate::getInstance()->goCheck(OrderGoodsDetailValidate::$pkId,$orderGoodsDetailBean->getData());
		// Todo:添加业务处理代码...


		$result = OrderGoodsDetailModel::getInstance()->deleteData([OrderGoodsDetailBean::$id => $orderGoodsDetailBean->getId()]);
		$result ?: MyException::throwMyException("删除失败");
		return $result;
	}
	
	/**
	 * @desc 根据主建获取数据
	 * @param OrderGoodsDetailBean $orderGoodsDetailBean
	 * @return OrderGoodsDetailBean $orderGoodsDetailBean
	 * @throws Exception
	**/
	public function getInfo($orderGoodsDetailBean) {
		OrderGoodsDetailValidate::getInstance()->goCheck(OrderGoodsDetailValidate::$pkId,$orderGoodsDetailBean->getData());
		// Todo:添加业务处理代码...


		$result = OrderGoodsDetailModel::getInstance()->selectData([OrderGoodsDetailBean::$id => $orderGoodsDetailBean->getId()]);
		$result ?: MyException::throwMyException("获取信息失败");
		$orderGoodsDetailBean->setData($result);
		return $orderGoodsDetailBean;
	}
}
